From: Greg Sabino Mullane Date: Sun, 17 Feb 2008 14:11:55 +0000 (+0000) Subject: Fix for bug 13004, in which the Postgres full-text search has too many results, X-Git-Tag: 1.31.0-rc.0~49464 X-Git-Url: http://git.cyclocoop.org/%28%5B%5E/404?a=commitdiff_plain;h=c07e337da68a87e7e877c65194778f4b098bf7c2;p=lhc%2Fweb%2Fwiklou.git Fix for bug 13004, in which the Postgres full-text search has too many results, so it throws an error. Created a "too many" class as an alternate search result to return, and consider any error in SearchPostgres when running the actual search as a "too many" problem. Not an ideal solution, but I'm not sure how to get at the error message without requiring a newer version of PHP. --- diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 08ca791c86..a69336238b 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -395,6 +395,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * (bug 12846) IE rtl.css issue in RTL wikis special:Preferences when selecting an LTR user language * (bug 13005) DISPLAYTITLE does not work on preview +* (bug 13004) Fix error on Postgres searches that return too many results. == Parser changes in 1.12 == diff --git a/includes/SearchEngine.php b/includes/SearchEngine.php index c25b9bdb28..c22e58d722 100644 --- a/includes/SearchEngine.php +++ b/includes/SearchEngine.php @@ -339,10 +339,19 @@ class SearchResultSet { } +/** + * @addtogroup Search + */ +class SearchResultTooMany { + ## Some search engines may bail out if too many matches are found +} + + /** * @addtogroup Search */ class SearchResult { + function SearchResult( $row ) { $this->mTitle = Title::makeTitle( $row->page_namespace, $row->page_title ); } diff --git a/includes/SearchPostgres.php b/includes/SearchPostgres.php index eb1ac31c8e..59110a5a73 100644 --- a/includes/SearchPostgres.php +++ b/includes/SearchPostgres.php @@ -37,11 +37,24 @@ class SearchPostgres extends SearchEngine { * @access public */ function searchTitle( $term ) { - $resultSet = $this->db->resultObject( $this->db->query( $this->searchQuery( $term , 'titlevector', 'page_title' ))); + $q = $this->searchQuery( $term , 'titlevector', 'page_title' ); + $olderror = error_reporting(E_ERROR); + $resultSet = $this->db->resultObject( $this->db->query( $q, 'SearchPostgres', true ) ); + error_reporting($olderror); + if (!$resultSet) { + // Needed for "Query requires full scan, GIN doesn't support it" + return new SearchResultTooMany(); + } return new PostgresSearchResultSet( $resultSet, $this->searchTerms ); } function searchText( $term ) { - $resultSet = $this->db->resultObject( $this->db->query( $this->searchQuery( $term, 'textvector', 'old_text' ))); + $q = $this->searchQuery( $term, 'textvector', 'old_text' ); + $olderror = error_reporting(E_ERROR); + $resultSet = $this->db->resultObject( $this->db->query( $q, 'SearchPostgres', true ) ); + error_reporting($olderror); + if (!$resultSet) { + return new SearchResultTooMany(); + } return new PostgresSearchResultSet( $resultSet, $this->searchTerms ); } diff --git a/includes/SpecialSearch.php b/includes/SpecialSearch.php index d28cea37e9..3ef6fab352 100644 --- a/includes/SpecialSearch.php +++ b/includes/SpecialSearch.php @@ -160,6 +160,15 @@ class SpecialSearch { $search->setNamespaces( $this->namespaces ); $search->showRedirects = $this->searchRedirects; $titleMatches = $search->searchTitle( $term ); + + // Sometimes the search engine knows there are too many hits + if ($titleMatches instanceof SearchResultTooMany) { + $wgOut->addWikiText( '==' . wfMsg( 'toomanymatches' ) . "==\n" ); + $wgOut->addHTML( $this->powerSearchBox( $term ) ); + $wgOut->addHTML( $this->powerSearchFocus() ); + wfProfileOut( $fname ); + return; + } $textMatches = $search->searchText( $term ); $num = ( $titleMatches ? $titleMatches->numRows() : 0 ) diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index ce8d60e6db..0d3d94bc22 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -1203,6 +1203,7 @@ Make sure that this change will maintain historical page continuity. 'searchsubtitleinvalid' => "You searched for '''$1'''", 'noexactmatch' => "'''There is no page titled \"\$1\".''' You can [[:\$1|create this page]].", 'noexactmatch-nocreate' => "'''There is no page titled \"\$1\".'''", +'toomanymatches' => 'Too many matches were returned, please try a different query', 'titlematches' => 'Page title matches', 'notitlematches' => 'No page title matches', 'textmatches' => 'Page text matches',